import type { TableColumn } from '@/components/core/dynamic-table';
import type { FormSchema } from '@/components/core/schema-form';
import { Tag } from 'ant-design-vue';
import { formatToDateTime } from '@/utils/dateUtil';

export type TableListItem = API.TodoEntity;
export type TableColumnItem = TableColumn<TableListItem>;

export const baseColumns: TableColumnItem[] = [
  {
    title: 'ToDo',
    dataIndex: 'value',
    width: 80,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 80,
    formItemProps: {
      component: 'Select',
      componentProps: {
        options: [
          {
            label: '完成',
            value: 1,
          },
          {
            label: '未完成',
            value: 0,
          },
        ],
      },
    },
    customRender: ({ record }) => {
      const enable = ~~record.status === 1;
      return <Tag color={enable ? 'green' : 'red'}>{enable ? '完成' : '未完成'}</Tag>;
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createdAt',
    width: 80,
    customRender: ({ record }) => {
      return formatToDateTime(record.createdAt);
    },
  },
  {
    title: '更新时间',
    dataIndex: 'updatedAt',
    width: 80,
    customRender: ({ record }) => {
      return formatToDateTime(record.updatedAt);
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'value',
    label: 'ToDo',
    component: 'Input',
    colProps: { span: 8 },
  },
];
